<template>
  <div class="reports">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <div id="myChart" style="height: 500px"></div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from 'echarts'
import {
  TitleComponent,
  ToolboxComponent,
  TooltipComponent,
  GridComponent,
  LegendComponent,
} from 'echarts/components'
import { LineChart } from 'echarts/charts'
import { UniversalTransition } from 'echarts/features'
import { CanvasRenderer } from 'echarts/renderers'

echarts.use([
  TitleComponent,
  ToolboxComponent,
  TooltipComponent,
  GridComponent,
  LegendComponent,
  LineChart,
  CanvasRenderer,
  UniversalTransition,
])

export default {
  data() {
    return {
      myChart: null,
      options: {
        title: {
          text: '用户来源',
        },

        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3',
            },
          },
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true,
        },
        xAxis: [
          {
            boundaryGap: false,
            name: '销售日期',
          },
        ],
        yAxis: [
			{
            type: 'value'
          }
		]
      },
    }
  },
  created() {
    this.getReportData()
  },
  mounted() {
    this.myChart = echarts.init(document.getElementById('myChart'))
  },
  methods: {
    async getReportData() {
      const { meta, data } = await this.$axios.get('/api/reports/type/1')
      if (meta.status == 200) {
        // this.option = data
        console.log(data)
      } else {
        this.$message.error('获取数据失败')
      }
      let opt = Object.assign(this.options, data)
      opt && this.myChart.setOption(opt)
    },
  },
}
</script>
